import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class text {
    public static void main1(String[] args) throws Exception {
        // 第一个时间点
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startTime = dateFormat.parse("2022-05-01 14:30:00");

        // 第二个时间点
        Calendar endTimeCal = Calendar.getInstance();
        endTimeCal.set(Calendar.YEAR, 2022);
        endTimeCal.set(Calendar.MONTH, Calendar.MARCH);
        endTimeCal.set(Calendar.DAY_OF_MONTH, 1);
        endTimeCal.set(Calendar.HOUR_OF_DAY, 9);
        endTimeCal.set(Calendar.MINUTE, 0);
        endTimeCal.set(Calendar.SECOND, 0);
        Date endTime = endTimeCal.getTime();

        long differenceInMillis = Math.abs(endTime.getTime() - startTime.getTime());
        int days = (int)(differenceInMillis / (1000 * 60 * 60 * 24));
        System.out.println(endTime);
        System.out.println("时间差为 " + days + " 天");
    }
    public static void main2(String[] args) {
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String date = formatter.format(System.currentTimeMillis());
        System.out.println("当前时间为：" + date);
    }
        public static void main(String[] args) {
            Date currentDate = new Date(); // 获取当前时间的日期对象

            long timeInMillis = currentDate.getTime(); // 获取日期对象表示的毫秒数
            int timestamp = (int)(timeInMillis / 1000); // 将毫秒数除以1000得到秒数并转换为整型

            System.out.println("Timestamp: " + timestamp);
        }
}
